<template>
  <div style="margin-top:30px;">
    <el-form ref="form" :model="form" :rules="rules" label-width="160px">
      <el-row>
        <el-col :span="24">
          <div class="grid-content bg-purple">
            <el-form-item v-for="config in form.roleConfigList" :label="config.configName" style="margin-right:15px">
              <el-switch :key="config.code" v-model="config.configValue" active-color="#13ce66" inactive-color="#DDDDDD" active-value="1" inactive-value="0" />
            </el-form-item>
          </div>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="funcCancel">取 消</el-button>
      <el-button type="primary" @click="funcSubmit">确 定</el-button>
    </div>
  </div>
</template>
<script>
import Vue from 'vue'
import 'xe-utils'
import VXETable from 'vxe-table'
import 'vxe-table/lib/index.css'
import request from '@/utils/request'
Vue.use(VXETable)
export default {
  name: 'RoleNotice',
  data() {
    return {
      emptyForm: {},
      form: {
        roleCode: '',
        roleConfigList: []
      },
      rules: {
        roleName: [
          { required: true, message: '请输入角色名称', trigger: 'blur' },
          
        ]
      }
    }
  },
  created() {
    // 保存空表单对象
    this.emptyForm = JSON.parse(JSON.stringify(this.form))
  },
  methods: {
    // 获取页面信息
    getInfo(code) {
      // 查询到数据之前先展示空表单
      this.form = JSON.parse(JSON.stringify(this.emptyForm))
      this.form.roleCode = code
      request({ url: `/arpa-basic-api/roleConfig`, method: 'get', params: { 'roleCode': code, 'type': 'notice' }}).then(response => {
        this.form.roleConfigList = response.data.records
      })
    },
    // 提交
    funcSubmit() {
      const data = this.form.roleConfigList
      request({ url: '/arpa-basic-api/roleConfig', method: 'put', data }).then(response => {
        this.$message({ message: response.msg, type: 'success' })
        this.funcCancel()
      })
    },
    // 取消
    funcCancel() {
      this.$emit('fatherCancelMethod', 'notice')
    }

  }
}
</script>
<style lang="scss" scoped>
  .dialog-footer {
    margin:15px 0 15px 0;
    width: 175px;
    float: right;
  }
</style>
